package com.wanmait.gohome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.gohome.mapper.AttentionMapper;
import com.wanmait.gohome.pojo.Attention;
import com.wanmait.gohome.pojo.Journal;
import com.wanmait.gohome.service.AttentionService;
import com.wanmait.gohome.util.SysContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class AttentionServiceImpl implements AttentionService {
    @Resource
    private AttentionMapper attentionMapper;

    @Override
    public void insert(Attention object) {

    }

    @Override
    public void update(Integer id) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public List<Attention> findAll() {
        return null;
    }

    @Override
    public Attention findById(Integer id) {
        return null;
    }

    @Override
    public PageInfo<Attention> findPage() {
        return null;
    }

    @Override
    public List<Attention> findAll(Attention object) {
        return null;
    }

    @Override
    public PageInfo<Attention> findPage(Attention object) {
        return null;
    }


    /**
     *
     * @param userId  个人中心 查询所有关注
     * @return
     */
    @Override
    public PageInfo<Attention> findByUserId(Integer userId) {
        int pageNum = SysContext.getPageNum();
        int pageSize = 15;
        PageHelper.startPage(pageNum, pageSize);
        List<Attention> attentions = attentionMapper.findByUserId(userId);
        PageInfo<Attention> pageInfo = new PageInfo<>(attentions, 5);
        return pageInfo;
    }


    /**
     *
     * @param userId
     * @param informationId   个人中心 取消关注
     */
    @Override
    public void deleteByUserIdAndInformationId(Integer userId, Integer informationId) {
        attentionMapper.deleteByUserIdAndInformationId(userId,informationId);
    }

    /**
     *
     * @param id  个人中心 首页  查找关注数量
     * @return
     */
    @Override
    public Integer findCountByUserId(Integer id)
    {
        return attentionMapper.findCountByUserId(id);
    }


    /**
     *
     * @param id
     * @param informationId  失踪详情页面 关注
     */
    @Override
    public void insert(Integer id, Integer informationId) {
        attentionMapper.insertAttention(id,informationId);
    }

    /**
     *
     * @param userId
     * @param informationId  查看是否关注
     * @return
     */
    @Override
    public Attention findByUserIdAndInformationId(Integer userId, Integer informationId) {
        return attentionMapper.findByUserIdAndInformationId(userId,informationId);
    }



}
